package chapter15;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/23 14:13
 */
public class MyExecutorTest {
    public static void main(String[] args) {
        MyExecutor executor = new MyExecutor();
        Callable<Integer> subTask = () -> {
            // 执行异步任务
            int millis = (int) (Math.random() * 100);
            TimeUnit.MILLISECONDS.sleep(millis);
            return millis;
        };

        //异步调用，返回一个MyFuture对象
        MyFuture<Integer> future = executor.execute(subTask);
        //...执行其他操作
        try {
            //获取异步调用的结果
            Integer result = future.get();
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
